#ifndef UTILITIES_H
#define UTILITIES_H

#include <cctype>
#include <string>

// Data structure for holding 3 numbers (e.g. 3D position or orientation)
typedef struct Triple
{
	float x;
	float y;
	float z;

	Triple( float xn = 0, float yn = 0, float zn = 0 )
		: x(xn), y(yn), z(zn)
	{
	}

	Triple( const Triple & n )
		: x( n.x ), y( n.y ), z( n.z )
	{
	}

	inline bool operator==( const Triple & rhs )
	{
		return ( x == rhs.x ) && ( y == rhs.y ) && ( z == rhs.z );
	}

	inline bool operator!=( const Triple & rhs )
	{
		return ! ( *this == rhs );
	}
} Triple;

typedef struct Color
{
	int r;
	int g;
	int b;

	Color( int rn = 0, int gn = 0, int bn = 0 )
	: r(rn), g(gn), b(bn)
	{
	}
} Color;


// Calculate the distance between two points.
float getDistance ( float x1 , float y1 , float z1 , float x2 , float y2 , float z2);
float getDistance ( const Triple & p1, const Triple & p2 );

// Returns a point between p1 and p2 using parameter t ranging from 0 to 1 to interpolate;
// using t = 0 would return p1, while t = 1 would return p2, and t = 0.5 would return the average
Triple interpolate( const Triple & p1, const Triple & p2, float t = 0.5 );

// Turn one object to face another
int turnToFace( int source, int target );

// Show the number of frames per second
void showFPS();


// Used to index into a 2D Grid
typedef struct Position
{
	union
	{
		int x;
		int i;
	};
	union
	{
		int j;
		int y;
		int z;
	};

	// Constructor
	Position( int xNew = 0, int yNew = 0)
		: x(xNew), y(yNew)
	{
	}

	// Copy constructor
	Position( const Position & pos )
	{
		x = pos.x;
		y = pos.y;
	}

	inline bool operator==( const Position & rhs ) const
	{
		return ( x == rhs.x ) && ( y == rhs.y );
	}

	inline bool operator!=( const Position & rhs ) const
	{
		return !( *this == rhs );
	}
} Position;

typedef struct Pose
{
	Triple position;
	Triple rotation;

	inline bool operator==( const Pose & rhs )
	{
		return ( position == rhs.position ) && ( rotation == rhs.rotation );
	}

	inline bool operator!=( const Pose & rhs )
	{
		return !( *this == rhs );
	}
} Pose;

Pose interpolate( Pose p1, Pose p2, float t = 0.5 );



//////////////////////////////////////////////////////////////////
// String functions from Amadeus on dreamincode.net

std::string StringToUpper(std::string strToConvert);

std::string StringToLower(std::string strToConvert);


#endif